/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.aratuk.converter;

import br.com.aratuk.modelo.Loteria;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author roniere
 */
@FacesConverter(value="conversorloteria")
public class ConversorLoteria  implements Converter {

    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
        if (value != null && !value.isEmpty()) {
            return (Loteria) uiComponent.getAttributes().get(value);
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
        if (value instanceof Loteria) {
            Loteria entity= (Loteria) value;
            if (entity != null && entity instanceof Loteria && entity.getId() != null) {
                uiComponent.getAttributes().put( entity.getId().toString(), entity);
                return entity.getId().toString();
            }
        }
        return "";
    }    
    
}
